#include<stdio.h>
#include<queue>
using namespace std;
const int maxn=10010;
priority_queue<int,vector<int>,greater<int> > q;
int main()
{
	int m,n,a[maxn],k=0;
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
		if(k<m)
			q.push(a[i]);
		k++;
	}
	int x,y;
	while(q.size()>1){
		x=q.top();
		q.pop();
		y=a[m++];
		if(m<=n)
			q.push(x+y);
	}
	printf("%d",q.top());
	return 0;
}
